﻿; (function ($, window, document, undefined) {
    //倒计时
    $.fn.countdown = function (timer, callback) {
        var obj = this;
        var setIn = window.setInterval(function () {
            var day = 0,
                hour = 0,
                minute = 0,
                second = 0; //时间默认值
            if (timer > 0) {
                day = Math.floor(timer / (60 * 60 * 24));
                hour = Math.floor(timer / (60 * 60)) - (day * 24);
                minute = Math.floor(timer / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(timer) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            var timebar = '';
            if (day != 0) {
                timebar += "天";
            }
            if (hour != 0) {
                timebar += hour + "时";
            }
            if (minute != 0) {
                timebar += minute + "分";
            }
            if (second != 0) {
                timebar += second + "秒";
            }
            obj.html(timebar);
            timer--;
            if (timer === -1) {
                stop();
            }
        }, 1000);
        function stop() {
            window.clearInterval(setIn);
            callback();
        }
    }
    $.extend({
        //过滤所有的Html标签
        filterHtml: function (str) {
            return str.replace(/(<[^>]*>)/g, "");
        },
        //过滤所有的空白符
        filterBlank: function (str) {
            return str.replace(/\s*/g, "");
        },
        //过滤json特殊字符
        filterJson: function (str) {
            return str.replace(/(")|(\\)|(\s*)/g, "");
        },
        //html提取纯文本
        filterAll: function (str) {
            return str.replace(/(")|(<[^>]*>)|(\s*)|(\\)/g, "");
        },
        //替换名字中间的字
        replaceNameToStar: function (str) {
            return str.replace(/(\S{1})\S{1}(\S*)/g, "$1*$2");
        },
        //替换身份证中间的数字
        replaceIDCardToStar: function (str) {
            return str.replace(/(\S{3})\S{11}(\S{4})/g, "$1***********$2");
        },
        //替换手机中间的数字
        replacePhoneToStar: function (str) {
            return str.replace(/(\S{3})\S{4}(\S{4})/g, "$1****$2");
        }
    });
})(jQuery, window, document);